using System;

namespace Framework.UI
{
    public class UIInputField : UIBase
    {
        private ExInputField mExInputField = null;

        public ExInputField ExInputField { get { return mExInputField; } }


        private Action<string> mOnValueChanged = null;
        private Action<string> mOnEndEdit = null;

        public Action<string> OnValueChanged
        {
            set
            {
                mOnValueChanged = value;
                if (value != null)
                    mExInputField.onValueChanged.AddListener(OnValueChangedInputField);
                else
                    mExInputField.onValueChanged.RemoveListener(OnValueChangedInputField);
            }
        }
        public Action<string> OnEndEdit
        {
            set
            {
                mOnEndEdit = value;
                if (value != null)
                    mExInputField.onEndEdit.AddListener(OnEndEditInputField);
                else
                    mExInputField.onEndEdit.RemoveListener(OnEndEditInputField);
            }
        }

        protected override void OnAwake()
        {
            mExInputField = GetComponent<ExInputField>("ExInputField");
        }

        private void OnValueChangedInputField(string pValue)
        {
            mOnValueChanged?.Invoke(pValue);
        }

        private void OnEndEditInputField(string pValue)
        {
            mOnEndEdit?.Invoke(pValue);
        }
    }
}